<template>
  <v-plain-dialog ref="edit">
    <el-form label-width="220px" label-position="right">
      <v-form-title title="修改利润配比"/>
      <el-form-item label="利润配比">
        <el-input-number
          size="mini"
          v-model="profitRatio"
          :precision="0"
          :step="1"
          :min="0"
          :controls="false"
          :max="100"/>
        %
      </el-form-item>
      <el-form-item>
        <el-button size="small" @click="edit(channelProvider.id,-1)">取消</el-button>
        <el-button size="small" type="primary" @click="edit(channelProvider.id,1)">确定</el-button>
      </el-form-item>
    </el-form>
  </v-plain-dialog>
</template>

<script lang="ts">
  import { Vue, Component } from 'vue-property-decorator'
  import vPlainDialog from '@/components/plain-dialog'
  import vFormTitle from '@/components/form-title'

  @Component({
    components: {
      vPlainDialog,
      vFormTitle
    }
  })
  export default class Merchants extends Vue {
    profitRatio = 0
    channelProvider = {}

    async edit (id,way) {
        if(way > 0){
            let res: AjaxResponse = await this.$axios.post('b/boms/channelprovider/updateprofitratio', {
                userId: id,
                profitRatio: this.profitRatio
            })
            this.$utils.tips(res)
            if (res.responseCode === 200) {
                this.$refs.edit.closeDialog()
                this.$emit('initList')
            }
        }else{
            this.$refs.edit.closeDialog()
            this.profitRatio = this.channelProvider.profitRatio
        }
    }

    openDialog (channelProvider) {
      this.channelProvider = channelProvider
      this.profitRatio = channelProvider.profitRatio
      this.$refs.edit.openDialog()
    }
  }
</script>

<style lang="less" scoped>
  
</style>
